<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-07-19 13:44
 *
 * Version: 2.0
 */

namespace App\Modules\Employee\Criterias;


use Flower\Core\Repository\Contracts\RepositoryInterface;
use Flower\Core\Repository\Criterias\BaseCriterias;
use Illuminate\Support\Facades\DB;

class GetWxLikePortfolioListCriteria extends BaseCriterias
{
	private $member_id;
	public function __construct($memberId)
	{
		$this->member_id = $memberId;
	}

	public function apply($model, RepositoryInterface $repository)
	{

		return $model->selectRaw('id,member_id,portfolio_id,created_at,count(id) as counts')->with('portfolio')->where('member_id','=',$this->member_id)->groupBy('portfolio_id')->orderBy('created_at','desc');


//		$ids = DB::table('user_portfolio_like')->where('member_id','=',$this->params['member_id'])->pluck('portfolio_id')->toArray();
//		$select = implode([
//            'hx_user_portfolio.id',
//           'hx_user_portfolio.user_id as barberId',
//            'hx_user_portfolio.name as portfolioName',
//            'hx_user_portfolio.service_id as serviceId',
//            'hx_user_portfolio.play_times as playTimes',
//            'hx_user_portfolio.created_at as date',
//            'IF(ISNULL(hx_user.`nick`),"Tony",hx_user.`nick`) as `barberName`',
//            'hx_picture.image as userPortraitUrl',
//            'hx_store_service.store_id as storeId',
//            'hx_store_service.name as serviceName',
//            'hx_store_service.price as servicePrice',
//            'hx_store.name as storeName',
//            'hx_store.address',
//            'hx_store.doorplate',
//            'hx_store.level as storeLevel'
//		],',');
//		return $model->selectRaw($select)
//			->with(['resource' => function ($query) {
//				$select = implode([
//					'hx_user_portfolio_resource.id',
//					'hx_user_portfolio_resource.portfolio_id',
//					'hx_user_portfolio_resource.resource_id',
//					'hx_user_portfolio_resource.type',
//					'CASE WHEN hx_user_portfolio_resource.type = 1 THEN null else hx_video.url END as videoUrl'
//				],',');
//				$query->selectRaw($select)
//					  ->leftJoin('video','user_portfolio_resource.resource_id','video.id');
//			}])
//			->leftJoin('store_service','user_portfolio.service_id' ,'store_service.id')
//			->leftJoin('store','store_service.store_id','store.id')
//			->leftJoin('user','user_portfolio.user_id','user.id')
//			->leftJoin('picture','user.portrait','picture.id')
//			->withCount(['userPortfolioLike'])
//			->whereIn('user_portfolio.id',$ids)->orderBy('id', 'desc');
	}

}
